<%@ page contentType="text/html; charset=utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>图书馆管理系统</title>
    <script type="text/javascript" src="js/jquery.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/book.js" charset="utf-8"></script>

  </head>
  <body>
  <center>
     <font size="10">图书馆管理系统</font><%--&nbsp;&nbsp;&nbsp;&nbsp;
	   <input type="button" value="登入" onclick="login()"><br><br>
	   --%>
<c:choose>
	<c:when test="${sessionScope.USER eq null}">
		|<a class=hot2 href="user!toLogin.action" id=login>登录</a>|
		<a class=hot2 href="user!toReg.action" id=regist>注册</a>|
	</c:when>
	<c:otherwise>
		您好：　${sessionScope.USER.username}
			&nbsp;| &nbsp; <A href="user!doLogout.action">注销</A> |
	</c:otherwise>
</c:choose>
	   <form action="allBook!toBookList.action" method="post" name="form1">
	    书名：
	   <input type="text" name="book.bookname"/>
	   <s:select list="#{1:'信息类',2:'娱乐类',3:'文学类',4:'历史类'}" name="book.bookkind"
						theme="simple" headerKey="0" headerValue="全部"></s:select>
	   <input type="button" onclick="query()" value="查询"/>
       <br><br><br>
		  	 <table border="0">
		  	 	<tr>
		  	 		<td>书籍编号</td>
		  	 		<td>书籍名称</td>
		  	 		<td>书籍种类</td>
		  	 		<td>操作</td>
		  	 	</tr>
		  	 	<s:if test="#request.SPB.size()==0">
					<tr>
						<td colspan="20"
							style="text-align: center; height: 40px;">
							暂时还没有记录
						</td>
					</tr>
				</s:if>
				<s:else>
					<s:iterator value="#request.SPB.datas" status="status" id="book1">
					<tr>
						<td>
							<s:property value="bookid"/>
						</td>
						<td>
							<s:property value="bookname"/>
						</td>
						<td align="center">
							<s:property value="bookkind"/>
						</td>
						<c:choose>						
						 <c:when test="${sessionScope.USER eq null}">
						    <td>
						 		<input type="button" value="借阅" onclick="login()"/>
							</td>
						</c:when>
						<c:otherwise>			
							 <td>
							    <input type="button" value="借阅" onclick="borrow(<s:property value="bookid"/>,${sessionScope.USER.userid})"/>
							</td>
						</c:otherwise>
						</c:choose>
					</tr>
				  </s:iterator>
					<tr>
						<th colspan="100" class="pager">

							<div class="pager">
                                <pg:pager url="allBook!toBookList.action" maxPageItems="4" maxIndexPages="6" items="${requestScope.SPB.total}" export="currentPageNumber=pageNumber">
									<pg:first>
										<a href="${pageUrl}">首页</a>
									</pg:first>
									<pg:prev>
										<a href="${pageUrl}">上一页</a>
									</pg:prev>
									
									<pg:pages>
										<s:if test="#attr.currentPageNumber==#attr.pageNumber">
											<font color="red">${pageNumber}</font>
										</s:if>
										<s:else>
											<a href="${pageUrl}">${pageNumber }</a>
										</s:else>
										
										
									</pg:pages>
									
									<pg:next>
										<a href="${pageUrl}">下一页</a>
									</pg:next>
									<pg:last>
										<a href="${pageUrl}">尾页</a>
									</pg:last>
								</pg:pager>
								
							</div>
						</th>
					</tr>		
				</s:else>
		  	 </table>
	 </form>
  </center>	 
  </body>
 </html>